<template>
  <aplid-base-crud ref="crud" class="w-100" v-bind="baseConfig" :paramsObj="{isWithAuth:props.isWithAuth}">
    <template v-slot:ArchivesDialog="{ row, show }">
      <Archives @refresh="handleRefresh" :api="baseConfig.api" :key="show" :nowRowData="row"></Archives>
    </template></aplid-base-crud>
</template>

<script setup lang="ts">
type Props = {
  isWithAuth?:any
}
let props = withDefaults(defineProps<Props>(),{
  isWithAuth:undefined
})
import { getAreaObj } from '@/utils/util'
import { detailConfig } from '@/views/datacenter/business/reformArchives/config'
import Archives from '@/views/datacenter/business/reformArchives/components/Archives/index.vue'
const stateDicData = [
  { label: '未完成', value: '0', type: 'danger' },
  { label: '进行中', value: '1', type: 'info' },
  { label: '已完成', value: '2', type: 'success' },
]
const baseConfig = {
  pageName: '适老化改造档案',
  dictcodes: ['ELDERLY_TYPE', 'ACCESS_LEVEL_COUNTRY', 'COMMON_FLAG'],
  rowKey: 'id',
  api: {
    index: 'view_dpElderlyRemould_page',
    detail: 'view_dpElderlyRemould_page',
  },
  auth: {
    index: 'view_dpElderlyRemould_page',
    detail: 'view_dpElderlyRemould_page',
  },
  menuBtn: [
    {
      icon: 'detail',
      label: '查看详情',
      type: 'primary',
      operate: 'Archives',
      auth: 'view_dpCommunityServiceOrder_page',
      text: true,
      show: true,
    },
  ],
  dialogConfig: {
    width: '90%',
    // fullscreen: true
  },
  detailConfig,
  tableConfig: {
    stripe: true,
    border: false,
    tableLayout: 'auto',
    columns: [
      {
        label: '申请档案',
        prop: 'applyState',
        custome: 'tag',
        dicData: stateDicData,
      },
      {
        label: '评估档案',
        prop: 'assessState',
        custome: 'tag',
        dicData: stateDicData,
      },
      {
        label: '改造档案',
        prop: 'remouldState',
        custome: 'tag',
        dicData: stateDicData,
      },
      {
        label: '验收档案',
        prop: 'acceptanceState',
        custome: 'tag',
        dicData: stateDicData,
      },
      {
        label: '操作',
        prop: 'menu',
        width: 200,
        fixed: 'right',
      },
    ],
  },
  onLoadFormate: async (arr) => {
    const tableData = arr.map((item) => {
      const crAreas: any = getAreaObj(item, 'cr', 'get')
      const areas: any = getAreaObj(item, '', 'get')
      return {
        ...item,
        crAreas: crAreas.areaIds,
        cr_areas: crAreas.names,
        areas: areas.areaIds,
        areas_name: areas.names,
      }
    })
    return Promise.resolve(Object.freeze(tableData))
  },
}
const crud = ref()
const handleRefresh = (query) => {
  nextTick(() => {
    crud.value.refreshChange(query)
  })
}
</script>

<style scoped></style>
